import 'package:casdon/core/logger/log.dart';
import 'package:casdon/core/network/business_exception.dart';
import 'package:casdon/modules/me/data/repository/me_repository.dart';
import 'package:casdon/modules/me/data/repository/me_repository_impl.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class ModifyUserInfoUscase {
  final MeRepository _repository;

  const ModifyUserInfoUscase(this._repository);

  Future<bool> execute({
    required String? nickName,
    required String? sex,
    required String? birthday,
    int? avatar,
  }) async {
    try {
      final _ = await _repository.putModifyUserInfo(
        nickName: nickName,
        sex: sex,
        birthday: birthday,
        avatar: avatar,
      );
      return true;
    } on BusinessException {
      rethrow;
    } catch (e) {
      Log.e("ModifyUserInfoUscase 失败", e.toString(), StackTrace.current);
      return false;
    }
  }
}

final modifyUserInfoUscaseProvider = Provider(
  (ref) => ModifyUserInfoUscase(ref.read(meRepositoryProvider)),
);
